﻿using System;
using System.Collections.Generic;
using Core.Common;
using Newtonsoft.Json;

namespace TTSClient.Models
{
    public class LanguageResponse<T>
    {
        public bool Flag { get; set; }
        public int Code { get; set; }
        public string Desc { get; set; }
        public ICollection<T> Data { get; set; }
    }

    public class Language
    {
        /// <summary>
        /// 发音人
        /// </summary>
        [JsonProperty("desc")]
        public string Name { get; set; }
        /// <summary>
        /// 语言名字
        /// </summary>
        [JsonProperty("languages")]
        public string Languages { get; set; }
        /// <summary>
        /// 男女声
        /// </summary>
        [JsonProperty("characteristic")]
        public string Characteristic { get; set; }
        /// <summary>
        /// 费用
        /// </summary>
        [JsonProperty("fee")]
        public string Fee { get; set; }
        /// <summary>
        /// 是否过期
        /// </summary>
        [JsonProperty("timeExpired")]
        public bool TimeExpired { get; set; }
        /// <summary>
        /// 过期时间
        /// </summary>
        [JsonProperty("validTime")]
        public DateTime ValidTime { get; set; }
        /// <summary>
        /// 授权状态
        /// </summary>
        [JsonProperty("licState")]
        public int LicState { get; set; }
        /// <summary>
        /// 包编号
        /// </summary>
        [JsonProperty("packageId")]
        public int PackageId { get; set; }

        [JsonProperty("id")]
        public LanguageId Id { get; set; }
        /// <summary>
        /// 扩展项
        /// </summary>
        [JsonProperty("extension")]
        public string ExtensionString { get; set; }
        /// <summary>
        /// 扩展项
        /// </summary>
        [JsonIgnore]
        public LanguageExtension Extension { get; set; }

        [JsonIgnore]
        public string Code => Id?.Code ?? Extension?.Code;
        [JsonIgnore]
        public string Text => Name + "-" + Languages + "-" + Extension?.Style ?? Characteristic;

        /// <summary>
        /// 设置扩展
        /// </summary>
        public void SetExtension()
        {
            try
            {
                Extension = ExtensionString.ToJsonObject<LanguageExtension>();
            }
            catch (Exception)
            {
                try
                {
                    var index = ExtensionString.IndexOf(",\"text\":");
                    ExtensionString = ExtensionString[0..index] + "}";
                    Extension = ExtensionString.ToJsonObject<LanguageExtension>();
                }
                catch (Exception)
                {
                }
            }
        }
    }

    public class PaymentLanguage
    {
        [JsonProperty("channel")]
        public string Channel { get; set; }
        /// <summary>
        /// 男女声
        /// </summary>
        [JsonProperty("characteristic")]
        public string Characteristic { get; set; }
        [JsonProperty("code")]
        public string Code { get; set; }
        /// <summary>
        /// 发音人
        /// </summary>
        [JsonProperty("desc")]
        public string Name { get; set; }
        /// <summary>
        /// 费用
        /// </summary>
        [JsonProperty("fee")]
        public string Fee { get; set; }
        /// <summary>
        /// 免费使用次数
        /// </summary>
        [JsonProperty("freeTimes")]
        public int FreeTimes { get; set; }
        [JsonProperty("function")]
        public string Function { get; set; }
        /// <summary>
        /// 语言名字
        /// </summary>
        [JsonProperty("languages")]
        public string Languages { get; set; }
        /// <summary>
        /// 授权状态
        /// </summary>
        [JsonProperty("licState")]
        public int LicState { get; set; }
        /// <summary>
        /// 包编号
        /// </summary>
        [JsonProperty("packageId")]
        public int PackageId { get; set; }
        [JsonProperty("riseStatus")]
        public bool RiseStatus { get; set; }
        /// <summary>
        /// 是否过期
        /// </summary>
        [JsonProperty("timeExpired")]
        public bool TimeExpired { get; set; }
        /// <summary>
        /// 过期时间
        /// </summary>
        [JsonProperty("validTime")]
        public DateTime ValidTime { get; set; }
        /// <summary>
        /// 版本号
        /// </summary>
        [JsonProperty("version")]
        public string Version { get; set; }

        /// <summary>
        /// 扩展项
        /// </summary>
        [JsonProperty("extension")]
        public string ExtensionString { get; set; }
        /// <summary>
        /// 扩展项
        /// </summary>
        [JsonIgnore]
        public LanguageExtension Extension { get; set; }
    }

    public class LanguageId
    {
        [JsonProperty("channel")]
        public string Channel { get; set; }
        [JsonProperty("code")]
        public string Code { get; set; }
        [JsonProperty("function")]
        public string Function { get; set; }
    }

    public class LanguageExtension
    {
        [JsonProperty("speaker")]
        public string Speaker { get; set; }
        [JsonProperty("type")]
        public string Type { get; set; }
        [JsonProperty("age")]
        public string Age { get; set; }
        [JsonProperty("style")]
        public string Style { get; set; }
        [JsonProperty("info")]
        public string Info { get; set; }
        [JsonProperty("code")]
        public string Code { get; set; }
        [JsonProperty("function")]
        public string Function { get; set; }
        [JsonProperty("name")]
        public string Name { get; set; }
        [JsonProperty("text")]
        public string Text { get; set; }
    }
}
